using UnityEngine;

public class Bullet : MonoBehaviour
{
	public float speed = 100f;

	public Vector3 moveDirection;

	public float damage;

	[SerializeField]
	protected CharacterInformation shooter;

	public ParticleSystem hitpar;

	public Rigidbody body => GetComponent<Rigidbody>();

	public void SetBullet(float damage, CharacterInformation shooter)
	{
		this.shooter = shooter;
		Transform transform = base.transform;
		Vector3 position = base.transform.position;
		float y = position.y;
		Vector3 position2 = base.transform.position;
		transform.position = new Vector3(0f, y, position2.z);
		Vector3 worldPosition = base.transform.position + base.transform.forward * 5f;
		worldPosition.x = 0f;
		base.transform.LookAt(worldPosition);
		this.damage = damage;
		moveDirection = base.transform.forward;
		body.velocity = base.transform.forward * speed;
	}

	protected virtual void FixedUpdate()
	{
		body.velocity = base.transform.forward * speed;
	}

	protected virtual void OnCollisionEnter(Collision collision)
	{
		if (collision.gameObject.CompareTag("KillOnTouch"))
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
		else
		{
			if (collision.rigidbody != null && collision.rigidbody.GetComponent<Weapon>() != null)
			{
				return;
			}
			if ((bool)collision.rigidbody)
			{
				float d = 15f;
				Rigidbody rigidbody = collision.rigidbody;
				CharacterPart component = rigidbody.GetComponent<CharacterPart>();
				BombCrate component2 = rigidbody.GetComponent<BombCrate>();
				if (component != null)
				{
					Vector3 force = d * moveDirection * 100f;
					component.TakeDamage(damage, shooter, force);
				}
				else if (component2 != null)
				{
					component2.Blow(shooter);
				}
				else if (hitpar != null)
				{
					hitpar.transform.parent = null;
					hitpar.Play();
					UnityEngine.Object.Destroy(hitpar.gameObject, 1.1f);
				}
			}
			else if (hitpar != null)
			{
				hitpar.transform.parent = null;
				hitpar.Play();
				UnityEngine.Object.Destroy(hitpar.gameObject, 1.1f);
			}
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}
}
